package com.yanqu.road.server.cmd.rank;

import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.config.PatronsMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ：zfr
 * @date ：2021/9/18 15:08
 */
@Cmd(code = GameProtocol.S_GET_PATRONS_RANK_DETAIL_INFO_FROM_CROSS, desc = "跨服来获取门客榜单门客详细信息")
public class GetPatronsRankDetailInfoCrossCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        RankProto.GetPatronsRankDetailInfoCrossReqMsg msg = RankProto.GetPatronsRankDetailInfoCrossReqMsg.parseFrom(packet.getBytes());
        String userPatronsDetailInfoJsonStr = PatronsMgr.getUserPatronsDetailInfoJsonStr(msg.getReqMsg().getUserId(), msg.getReqMsg().getPatronsId());
        RankProto.GetPatronsRankDetailInfoRespMsg.Builder builder = RankProto.GetPatronsRankDetailInfoRespMsg.newBuilder();
        builder.setPatronsInfoJsonStr(userPatronsDetailInfoJsonStr);
        RankProto.GetPatronsRankDetailInfoCrossRespMsg.Builder respMsg = RankProto.GetPatronsRankDetailInfoCrossRespMsg.newBuilder();
        respMsg.setRespMsg(builder);
        respMsg.setFromServerId(msg.getFromServerId());
        respMsg.setFromUserId(msg.getFromUserId());
        YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_GET_PATRONS_RANK_DETAIL_INFO_RETURN, respMsg);
        GamePlayerMgr.sendPacket(0, message);
    }
}
